package com.zhledu.phone;

import com.zhledu.wordcount.WordCountDriver;
import com.zhledu.wordcount.WordCountMapper;
import com.zhledu.wordcount.WordCountReduce;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.net.URI;

public class PhoneDriver {
    public static void main(String[] args) throws Exception {
        Configuration conf=new Configuration();
        FileSystem fs=FileSystem.get(new URI("hdfs://master:9000"),conf);
        Path outPath=new Path(args[1]);
        if(fs.exists(outPath)) {
            fs.delete(outPath,true);
        }
        Job job=Job.getInstance(conf,"phone");
        //制定打成jar包后的运行类
        job.setJarByClass(PhoneDriver.class);
        //指定Mapper,Reduce类
        job.setMapperClass(PhoneMapper.class);
        job.setReducerClass(PhoneReduce.class);
        //指定Maper过程的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);
        //指定最后输出的类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, outPath);
        System.exit(job.waitForCompletion(true)?0:1);
    }

}
